/*
 * 流程控制js
 */
$(function() {

	// 选人发送
	$('body').on('click', '.send-with-user', function() {
		var $this = $(this);

		// 业务数据
		var id = $this.data('id');
		var flowtype = $this.data('flowtype');
		var rolecode = $this.data('rolecode');
		var status = $this.data('status');
		var single = $this.data('single') || true;

		$.suredy.showModal({
			icon : 'icon-signout',
			title : '选人发送' + (single ? '（单选）' : '（多选）'),
			showFoot : false,
			uri : $.suredy.contextPath + '/flow/send-with-user/' + flowtype + '/' + rolecode + '/' + id + '/' + status + '/' + single
		});
	});

	// 直接发送，相当于修改状态
	$('body').on('click', '.change-status', function() {
		if (!window.confirm('确认此操作么！'))
			return false;

		var $this = $(this);

		// 业务数据
		var id = $this.data('id');
		var flowtype = $this.data('flowtype');
		var status = $this.data('status');

		$.ajax({
			url : $.suredy.contextPath + '/flow/change-status',
			data : {
				id : id,
				type : flowtype,
				status : status
			},
			type : 'post',
			dataType : 'json',
			success : function(result, textStatus, jqXHR) {
				if (!result || !result.success) {
					alert(result.msg || '操作失败！');
					return false;
				}

				$.suredy.refreshContent(id, [ '.suredy-tabs' ]);
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert('操作失败！\n\n' + errorThrown);
			}
		});
	});

});